/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.tenant.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.siufung.core.model.VerifyRepeatDto;
import net.siufung.core.model.enums.MethodEventEnum;
import net.siufung.market.base.tenant.mapper.entity.TenantType;
import net.siufung.mybatis.base.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

/**
 * <p>
 * 系统租户类型表 Mapper 接口
 * </p>
 *
 * @author 陈建峰
 * @since 2022-07-06 14:45:08
 */
@Mapper
public interface ITenantTypeMapper extends BaseMapper<TenantType> {

    /**
     * 判断租户类型名称重复
     * @param verifyRepeatDto 验证视图
     * @return boolean
     */
    default boolean checkNameNotRepeat(VerifyRepeatDto<Integer> verifyRepeatDto) {
        if(verifyRepeatDto.getMethodEventEnum().equals(MethodEventEnum.ADD)){
            return 0L == this.selectCount(new LambdaQueryWrapper<TenantType>()
                    .eq(TenantType::getName, verifyRepeatDto.getVerifyKeyValue()));
        } else if(verifyRepeatDto.getMethodEventEnum().equals(MethodEventEnum.UPDATE)){
            return 0L == this.selectCount(new LambdaQueryWrapper<TenantType>()
                    .eq(TenantType::getName, verifyRepeatDto.getVerifyKeyValue())
                    .ne(TenantType::getId, verifyRepeatDto.getPk()));
        }
        return Boolean.FALSE;
    }

    /**
     * 判断租户编码名称重复
     * @param verifyRepeatDto 验证视图
     * @return boolean
     */
    default boolean checkCodeNotRepeat(VerifyRepeatDto<Integer> verifyRepeatDto) {
        if(verifyRepeatDto.getMethodEventEnum().equals(MethodEventEnum.ADD)){
            return 0L == this.selectCount(new LambdaQueryWrapper<TenantType>()
                    .eq(TenantType::getCode, verifyRepeatDto.getVerifyKeyValue()));
        } else if(verifyRepeatDto.getMethodEventEnum().equals(MethodEventEnum.UPDATE)){
            return 0L == this.selectCount(new LambdaQueryWrapper<TenantType>()
                    .eq(TenantType::getCode, verifyRepeatDto.getVerifyKeyValue())
                    .ne(TenantType::getId, verifyRepeatDto.getPk()));
        }
        return Boolean.FALSE;
    }

}
